package com.winphone.weekly.controller;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.winphone.weekly.entity.AcDatasourceConfig;
import com.winphone.weekly.service.IAcDatasourceConfigService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;



/**
 * @author: zhou
 * @Description:
 * @Date:Create in 2017/11/10
 * @Modified By:
 */
@Controller
@RequestMapping(value = "dbSources")
public class DBSourcesController{

    @Autowired
    private IAcDatasourceConfigService acDatasourceConfigService;


    @RequestMapping(value = "/toIndex")
    public String toDbIndex(){
        return "/db/dbsources";
    }



    @RequestMapping(value = "/sources")
    @ResponseBody
    public Object pageSources(AcDatasourceConfig acDatasourceConfig,
                              @RequestParam(value = "current",required = false) Integer current,
                              @RequestParam(value = "size",required = false) Integer size){
        Wrapper<AcDatasourceConfig> driverWrapper = new EntityWrapper<>(acDatasourceConfig);
        if (null == current){
            current = 0;
        }
        if (null == size){
            size = 10;
        }
        Page<AcDatasourceConfig> page = acDatasourceConfigService.selectPage(new Page<>(current,size),driverWrapper);

        return page;
    }
}
